package cn.disicn.Interceptors;

import com.jfinal.aop.Interceptor;
import com.jfinal.aop.Invocation;
import com.jfinal.core.Controller;
import cn.disicn.common.Const;
import cn.disicn.model.SecAdminUser;

/**
 * @author zjk
 * @date 2017年12月20日 上午11:20:04
 * @desc
 * 
 */
public class LoginInterceptor implements Interceptor {

	private static final SecAdminUser secAdminuser = new SecAdminUser();

	@Override
	public void intercept(Invocation inv) {
		Controller controller = inv.getController();
		try {
			SecAdminUser adminUserc = controller
					.getSessionAttr(Const.UserType.CURRENT_ADMIN);
			if (adminUserc != null) {
				if (secAdminuser.getSecAdminUserByUserName(adminUserc.getUserName()).isSuccess()) {
					inv.invoke();
					return;
				}
			}
			controller.redirect("/adminLogin");
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
	}
}
